<?php


include_once "../config.php";





$emp=select_lines_all_items($table_Prefix."employee","","status = '在职'","");




$url = 'http://wx.enpingshi.com/send_teambition_task_of_oa_msg.php';



//循环发送微信通知
foreach ($emp as $k=>$v)
{

    echo "<br/><br/><br/><br/><br/><br/><br/><br/>当前用户".$v['name'].$v['openid']."";

            $post_data = array(
                            "touser"=>$v['openid'], //推送给谁,openid
                            //"touser"=>'oUaqG0dZdR4ITehiwDOLoCxcn49w', //推送给工作号
                            "template_id"=>"zvH8KjMX3lrQxKVROe8Oo41Y9XN_Hk4OCfUZ0IozWgs", //微信后台的模板信息id
                            "url"=>"http://oa.enpingshi.com/controlbase/employee/detail-statistic-report-weekly.php?openid=".$v['openid'], //
                            "data"=> array(
                                "first" => array(
                                    "value"=>"本周周报已经生成，请查看",
                                    "color"=>"#173177"
                                ),
                                "keyword1"=>array(
                                    "value"=>date("Y-m-d"),//时间
                                    "color"=>"#173177"
                                ),

                                "keyword2"=>array(
                                    "value"=>"周报通知",
                                    "color"=>"#173177"
                                ),
                                "remark"=> array(
                                    "value"=>"点击本通知跳转到页面查看周报详情；",
                                    "color"=>"#173177"
                                ),
                            )
            );
			
			$sql_data = serialize($post_data);	
			$data['content'] = $sql_data;
			$re_back = send_wx_sms($url , $data);
			$re_back_arr = json_decode($re_back, true);
			
			echo $re_back;

}
			

function send_wx_sms($url , $info)
{
    $res =  request_post($url, $info);
    return $res;
}



function request_post($url = '', $post_data = array()) {
        if (empty($url) || empty($post_data)) {
            return false;
        }
        
        $o = "";
        foreach ( $post_data as $k => $v ) 
        { 
            $o.= "$k=" . urlencode( $v ). "&" ;
        }
        $post_data = substr($o,0,-1);

        $postUrl = $url;
		
        $curlPost = $post_data;
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        $data = curl_exec($ch);//运行curl
        curl_close($ch);
       
        return $data;
}






?>

